home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / rkrm_lib2 / rkrm_lib2.lha / Exec_Library / Signals / signals.c < prev   
C/C++ Source or Header  |  1992-09-03  |  4KB  |  115 lines

  1. ;/* signals.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 signals.c
  3. Blink FROM LIB:c.o,signals.o TO signals LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit ;
  5.  
  6.  
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/memory.h>
  34. #include <dos/dos.h>
  35.  
  36. #include <clib/exec_protos.h>
  37. #include <clib/dos_protos.h>
  38. #include <clib/alib_protos.h>
  39. #include "stdio.h"
  40.  
  41. #ifdef LATTICE
  42. int CXBRK(void) { return(0); }     /* Disable Lattice CTRL/C handling */
  43. int chkabort(void) { return(0); }  /* really */
  44. #endif
  45.  
  46. static UBYTE *VersTag = "$VER: signals 37.1 (28.3.91)";
  47.  
  48. void subtaskcode(void);    /* prototype for our subtask routine */
  49.  
  50. LONG  mainsignum = -1;
  51. ULONG mainsig, wakeupsigs;
  52. struct Task *maintask = NULL, *subtask = NULL;
  53. UBYTE subtaskname[] = "RKM_signal_subtask";
  54.  
  55. void main(int argc, char **argv)
  56. {
  57. BOOL Done = FALSE, WaitingForSubtask = TRUE;
  58.  
  59. /* We must allocate any special signals we want to receive. */
  60. mainsignum = AllocSignal(-1);
  61. if(mainsignum == -1)
  62.     printf("No signals available\n");
  63. else
  64.     {
  65.     mainsig = 1L << mainsignum;    /* subtask can access this global */
  66.     maintask = FindTask(NULL);     /* subtask can access this global */
  67.  
  68.     printf("We alloc a signal, create a task, wait for signals\n");
  69.     subtask = CreateTask(subtaskname, 0L, subtaskcode, 2000);
  70.     if(!subtask)
  71.         printf("Can't create subtask\n");
  72.     else
  73.         {
  74.         printf("After subtask signals, press CTRL-C or CTRL-D to exit\n");
  75.  
  76.         while((!Done)||(WaitingForSubtask))
  77.             {
  78.             /* Wait on the combined mask for all of the signals we are
  79.              * interested in.  All processes have the CTRL_C thru CTRL_F
  80.              * signals.  We're also Waiting on the mainsig we allocated
  81.              * for our subtask to signal us with.  We could also Wait on
  82.              * the signals of any ports/windows our main task created ... */
  83.  
  84.             wakeupsigs = Wait(mainsig | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
  85.  
  86.             /* Deal with all signals that woke us up - may be more than one */
  87.             if(wakeupsigs & mainsig)
  88.                 {
  89.                 printf("Signalled by subtask\n");
  90.                 WaitingForSubtask = FALSE;   /* OK to kill subtask now */
  91.                 }
  92.             if(wakeupsigs & SIGBREAKF_CTRL_C)
  93.                 {
  94.                 printf("Got CTRL-C signal\n");
  95.                 Done = TRUE;
  96.                 }
  97.             if(wakeupsigs & SIGBREAKF_CTRL_D)
  98.                 {
  99.                 printf("Got CTRL-D signal\n");
  100.                 Done = TRUE;
  101.                 }
  102.             }
  103.         Forbid();
  104.         DeleteTask(subtask);
  105.         Permit();
  106.         }
  107.     FreeSignal(mainsignum);
  108.     }
  109. }
  110.  
  111. void subtaskcode(void)
  112.     {
  113.     Signal(maintask,mainsig);
  114.     Wait(0L);    /* safe state in which this subtask can be deleted */
  115.     }